package logic_settings_user

import (
	v1 "Sailor/app/Sailor-console-server/api/api_task/v1"
	"Sailor/app/Sailor-console-server/internal/dao"
	"Sailor/app/Sailor-console-server/utility/utility_task"
	"context"
	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
)

func (s *sTask) LogicTaskDelete(ctx context.Context, req *v1.TaskDeleteReq) (res *v1.TaskDeleteRes, err error) {

	// 从任务列表中移除
	for _, v := range req.Uuid {
		utility_task.Remove(v)
	}

	_, err = dao.SysTask.Ctx(ctx).Where(dao.SysTask.Columns().Uuid, req.Uuid).Delete()
	if err != nil {
		g.Log().Error(ctx, err)
		return nil, gerror.New("删除失败")
	}
	return &v1.TaskDeleteRes{}, nil
}
